<?php

namespace App\Kuafu\Mybank\Resources;

use App\Http\Resources\BaseResource;
use App\Kuafu\Mybank\Model\MybankEntryModel;
use Carbon\Carbon;

class MybankEntryListResource extends BaseResource
{
    public function toArray($request)
    {
        return [
            "id"                 => $this->id,
            "outOrderNo"         => $this->outOrderNo,
            "orderNo"            => $this->orderNo,
            "outMerchantId"      => $this->outMerchantId,
            "type"               => $this->type,
            "typeText"           => translateEnumCodeToCn(MybankEntryModel::TYPE_TEXT, $this->type),
            "merchantId"         => $this->merchantId,
            "merchantType"       => $this->merchantType,
            "merchantTypeText"   => translateEnumCodeToCn(MybankEntryModel::MERCHANT_TYPE_TEXT,
                $this->merchantType),
            "merchantName"       => $this->merchantName,
            "contactMobile"      => $this->contactMobile,
            "contactName"        => $this->contactName,
            "principalMobile"    => $this->principalMobile,
            "principalCertType"  => $this->principalCertType,
            "principalCertNo"    => $this->principalCertNo,
            "principalPerson"    => $this->principalPerson,
            "bussAuthType"       => $this->bussAuthType,
            "bussAuthNo"         => $this->bussAuthNo,
            "bussAuthVld"        => $this->bussAuthVld,
            "status"             => $this->status,
            "statusText"         => translateEnumCodeToCn(MybankEntryModel::STATUS_TEXT, $this->status),
            "withholdStatus"     => $this->withholdStatus,
            "withholdStatusText" => translateEnumCodeToCn(MybankEntryModel::WITHHOLD_STATUS_TEXT,
                $this->withholdStatus),
            "withholdOpenAt"     => formatDate($this->withholdOpenAt),
            "withholdCloseAt"    => formatDate($this->withholdCloseAt),
            "createdAt"          => formatDate($this->createdAt->timestamp),
            "updatedAt"          => formatDate($this->updatedAt->timestamp),
            'shopBindList'       => $this->eachShopBindList($this->shopBindInfoRel)
        ]; // TODO: Change the autogenerated stub
    }

    public function eachShopBindList($item)
    {
        $return = [];
        if (!empty($item)) {
            foreach ($item as $itemOne) {
                $return[] =
                    [
                        'id'       => $itemOne->id,
                        'name'     => $itemOne->name,
                        'shopCode' => $itemOne->shopCode,
                    ];
            }
        }

        return $return;
    }
}
